package com.yesjpt.web;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.yesjpt.domain.book;
import com.yesjpt.serv.BookServ;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookServ serv;
    // 根据书籍名称查询
    @GetMapping("/findByName")
    public book findByName(String NAME) {
        System.out.println(new Throwable().getStackTrace()[0] + "， NAME = " + NAME);
        return serv.findByName(NAME);
    }

    // 根据ID查询
    @RequestMapping("/findById")
    public book findById(String id) {
        System.out.println(new Throwable().getStackTrace()[0]);
        book vo = serv.findById(id);
        System.out.println("vo.name = " + vo.getName());
        return vo;
    }

    // 根据ID删除
    @DeleteMapping("/deleteById")
    public JSONObject deleteById(String id) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.deleteById(id);
    }

    // 根据ID删除
    @GetMapping("/del")
    public JSONObject del(String id) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.deleteById(id);
    }
    // 新增
    @PostMapping("/add")
    public JSONObject add(@RequestBody book vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.add(vo);
    }

    // 更新
    @PutMapping("/update")
    public JSONObject update(@RequestBody book vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.update(vo);
    }

    // 列出全部http://localhost:8086/book/listAll
    @GetMapping("/listAll")
    public List<book> listAll() {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.listAll();
    }
}
